﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Text;
using System.Windows.Forms;
using foursquare.Foursquare;

namespace foursquare.Forms
{
    public partial class CheckinPanel : UserControl
    {
        public CheckinPanel(Checkin c)
        {
            InitializeComponent();
            Create(c);

        }

        public void Create(Checkin c)
        {
            Rectangle rect = this.ClientRectangle;

            LinkLabel lblCheckin = new LinkLabel();
            lblCheckin.Text = c.display;
            lblCheckin.Width = rect.Width;
            int rowHeight = (int)CFMeasureString.MeasureString(lblCheckin, lblCheckin.Text, rect).Height;

            lblCheckin.Height = rowHeight;
            lblCheckin.Tag = c.venue.id;
            lblCheckin.Click += new EventHandler(lblCheckin_Click);
            lblCheckin.Dock = DockStyle.Bottom;
            this.Controls.Add(lblCheckin);

            if (!String.IsNullOrEmpty(c.shout))
            {
                Label lblShout = new Label();
                lblShout.Text = c.shout;
                lblShout.Width = rect.Width;
                lblShout.Height = rowHeight;
                lblShout.Dock = DockStyle.Bottom;
                this.Controls.Add(lblShout);
            }

            LinkLabel lblCreated = new LinkLabel();
            lblCreated.Text = c.created.ToLocalTime().ToString();
            lblCreated.TextAlign = ContentAlignment.TopRight;
            lblCreated.Width = rect.Width;
            lblCreated.Height = rowHeight;
            if (c.user != null)
            {
                lblCreated.Tag = c.user.id;
                lblCreated.Click += new EventHandler(lblUser_Click);
            }
            lblCreated.Dock = DockStyle.Bottom; 
            this.Controls.Add(lblCreated);

            this.Height = rowHeight * this.Controls.Count + 2;
        }

        private void lblCheckin_Click(object sender, EventArgs e)
        {
            LinkLabel lbl = (LinkLabel)sender;
            VenueView view = new VenueView(lbl.Tag.ToString());
            view.Show();
        }

        private void lblUser_Click(object sender, EventArgs e)
        {
            LinkLabel lbl = (LinkLabel)sender;
            UserView view = new UserView(lbl.Tag.ToString());
            view.Show();
        }

    }
}
